﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Web;
using System.Collections.Specialized;

namespace KC.Business.ModuTweet
{
	public class Lookups
	{
		public static string ApiURL = @"https://api.twitter.com/1/"; // https://api.twitter.com/1/statuses/home_timeline.json   // include_entities=true&page=2
		public static string ApiKey = @"";
		public static string GetTimeline(string username, int qty, bool IncludeRetweets, bool IncludeReplies) {
			WebClient client = new WebClient();
			NameValueCollection nvc = new System.Collections.Specialized.NameValueCollection();
			nvc.Add("count", qty.ToString());
			nvc.Add("include_rts", IncludeRetweets.ToString());
			nvc.Add("include_entities", "true");
			nvc.Add("username", username);
			
			// BuyURLPostData = "apikey={0}&username={1}&password={2}&ticker={3}&shares={4}&last_trade={5}";
			string url = BuildQuerystring(@"statuses/home_timeline.json", nvc);
			byte[] bytes = client.UploadValues(url, "POST", nvc);
			return System.Text.Encoding.ASCII.GetString(bytes);
		}



		private static string BuildQuerystring(string query, NameValueCollection nvc)
		{
			string values = ApiURL + query + "?";
			foreach (string key in nvc.AllKeys)
				values += key + "=" + HttpUtility.UrlEncode(nvc[key]) + "&";
			return values.TrimEnd(new char[] { '&' });
		}
	}
}
